package com.jacky.proxy;

/**
 * 代理模式之：静态代理
 * 创建时期，在程序运行前代理类的.class文件就已经存在了
 */
public class StaticProxyTest {
    public static void main(String[] args) {
        Proxy proxy = new Proxy();
        proxy.Request();
    }
}

interface Subject {
    void Request();
}

class RealSubject implements Subject{

    @Override
    public void Request() {
        System.out.println("RealSubject:Request()");
    }
}

/**
 * 代理类实现了真实类的接口，
 * 也组合了真实类的接口，
 */
class Proxy implements Subject{
    private RealSubject realSubject;

    @Override
    public void Request() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        System.out.println("pre");
        realSubject.Request();
        System.out.println("post");
    }
}